package edu.service;

import java.util.List;

import edu.dao.PatientFormDAO;
import edu.model.Form;
import edu.model.Patient;
import edu.model.PatientForm;



public class PatientFormService {
	
	private int pfId;
	private int patientId;
	private Patient patient;
	private PatientForm patientForm;
	
	private PatientFormDAO patientFormDAO = null;
	
	public int getPatientId() {
		return patientId;
	}
	public void setPatientId(int patientId) {
		this.patientId = patientId;
	}
	public int getPfId() {
		return pfId;
	}
	public void setPfId(int pfId) {
		this.pfId = pfId;
	}
	public PatientForm getPatientForm() {
		return patientForm;
	}
	public void setPatientForm(PatientForm patientForm) {
		this.patientForm = patientForm;
	}
	public Patient getPatient() {
		return patient;
	}
	public void setPatient(Patient patient) {
		this.patient = patient;
	}
	public PatientFormDAO getPatientFormDAO() {
		return patientFormDAO;
	}
	public void setPatientFormDAO(PatientFormDAO patientFormDAO) {
		this.patientFormDAO = patientFormDAO;
	}
	
	public PatientForm getPatientFormById(int pfId) {
		return patientFormDAO.findById(pfId);
	}
	
	public void deletePatient(PatientForm patientForm) {
		patientFormDAO.delete(patientForm);
		return;
	}
	
	@SuppressWarnings("unchecked")
	public List<PatientForm> getPatientForm(Patient patient) {
		List forms =  patientFormDAO.findByProperty("patient", patient);
		return forms;
	}
	
	public PatientForm getPatientForm(Patient patien, Form form, int month) {
		List<PatientForm> forms =  getPatientForm(patien);
		
		for(int i = 0; i < forms.size(); i++) {
			if((int)form.getFormId() == (int)forms.get(i).getForm().getFormId()
					&& month == (int)forms.get(i).getMonth()) {
				return forms.get(i);
			}
		}
		return null;
	}
	
	public void save(PatientForm patientForm) {
		// TODO Auto-generated method stub
		patientFormDAO.save(patientForm);
	}
	
	public void update(PatientForm patientForm) {
		// TODO Auto-generated method stub
		patientFormDAO.attachDirty(patientForm);
	}

}